//
//  sumbitTweetViewController.m
//  twittsTab2
//
//  Created by Steven Hamilton on 3/4/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "sumbitTweetViewController.h"
#import "FirstViewController.h"



@implementation sumbitTweetViewController

@synthesize inputText, submit, countLabel;


-(IBAction) submitTweet:(id) sender{
	//NSString *text;
	
	
	//TwitterRequest *t = [[TwitterRequest alloc] init];
	//t.username = @"CHCProject";
	//t.password = @"team22";
	
	
	[inputText resignFirstResponder];
	
	
	[tr statuses_update:inputText.text delegate:self requestSelector:@selector(statuses_updateCallback:)];
	
}


- (void)status_updateCallback: (NSData *) content
{
	NSLog(@"%@", [[NSString alloc] initWithData:content encoding:NSASCIIStringEncoding]);
	
}

-(IBAction) updateLength:(id) sender{
	UITextField * textField = (UITextField *) sender;
	int maxChars = 140;
	int charsLeft = maxChars -[textField.text length];
	
	if(charsLeft == 0) {
		UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"No more characters"
														 message:[NSString stringWithFormat:@"You have reached the character limit of %d.",maxChars]
														delegate:nil
											   cancelButtonTitle:@"Ok"
											   otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	
	countLabel.text = [NSString stringWithFormat:@"%d character remaining.", charsLeft];
	
	
}



/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
